# 导包
import time

from selenium.webdriver.common.by import By
from base.page_base import BasePage
from config import BASE_URL


class Register(BasePage):
    """类属性"""
    phone = By.ID, "phone"
    password = By.ID, "password"
    verifycode = By.ID, "verifycode"
    get_phone_code = By.ID, "get_phone_code"
    phone_code = By.ID, "phone_code"
    lg_btn = By.CLASS_NAME, "lg-btn"
    success_text =(By.XPATH,"//*[text()='注册成功！']")
    error_text = (By.CLASS_NAME,'reg-title')
    def open_url(self):
        self.driver.get(BASE_URL+'/common/member/reg')
    def input_phone(self, phone):
        """输入手机号"""
        self.base_input(self.phone,phone)
    def input_password(self, password):
        """输入密码"""
        self.base_input(self.password,password)

    def input_verifycode(self, verifycode='8888'):
        """输入验证码"""
        self.base_input(self.verifycode,verifycode)
    def click_get_phone_code(self):
        """点击获取手机验证码"""
        self.base_click(self.get_phone_code)
    def input_phone_code(self,phone_code='666666'):
        """输入短信验证码"""
        self.base_input(self.phone_code,phone_code)
    def click_lg_btn(self):
        """点击注册按钮"""
        self.base_click(self.lg_btn)
    def get_success_text(self):
        """获取注册成功文本"""
        return self.fd_element(self.success_text).text
    def get_error_text(self):
        """获取注册失败文本"""
        return self.fd_element(self.error_text).text
    def register(self,phone,password,verifycode='8888',phone_code='666666'):
        self.input_phone(phone)
        self.input_password(password)
        self.input_verifycode(verifycode)
        self.click_get_phone_code()
        time.sleep(2)
        self.input_phone_code(phone_code)
        self.click_lg_btn()

